﻿using LogAnalyzer.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace LogAnalyzer.View
{
    /// <summary>
    /// Interaction logic for GraphView.xaml
    /// </summary>
    public partial class GraphView : UserControl
    {
        public IGraphViewModel ViewModel
        {
            get 
            {
                return this.DataContext as IGraphViewModel; 
            } 
        }

        public string TabHeader
        {
            get { return ViewModel.Header; }
        }

        public GraphView()
        {
            InitializeComponent();
            DataContextChanged += GraphView_DataContextChanged;
            join.Click += join_Checked;
            response.Click += response_Checked;
            done.Click += done_Checked;
        }

        void done_Checked(object sender, RoutedEventArgs e)
        {
            var vm = ViewModel as JoinGraphViewModel;
            if (vm != null)
            {
                vm.ShowJoinDone = done.IsChecked.Value;
                vm.Refresh();
            }
        }

        void response_Checked(object sender, RoutedEventArgs e)
        {
            var vm = ViewModel as JoinGraphViewModel;
            if (vm != null)
            {
                vm.ShowJoinResponse = response.IsChecked.Value;
                vm.Refresh();
            }
        }

        void join_Checked(object sender, RoutedEventArgs e)
        {
            var vm = ViewModel as JoinGraphViewModel;
            if (vm != null)
            {
                vm.ShowJoin = join.IsChecked.Value;
                vm.Refresh();
            }
        }

        void GraphView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var vm = ViewModel as GraphViewModel;
            if (vm == null)
                checks.Visibility = System.Windows.Visibility.Visible;
            else
                checks.Visibility = System.Windows.Visibility.Collapsed;
        }
    }
}
